<template>
  <div class="dog" style="user-select: none;">
    <div class="dog-img">
      <img :src="src" alt="" />
    </div>
    <p class="dog-desc" :style="{ color }" @click="handleClick(desc)">
      {{ desc }}
    </p>
  </div>
</template>

<script>
export default {
  name: 'Djwzbs',
  props: {
    src: {
      type: String,
      default: require('../assets/images/dva.png'),
    },
    desc: {
      type: String,
      default: '这是一只可怜的狗',
    },
  },
  data() {
    const color = this.getRandomColor()
    return {
      color,
    }
  },
  methods: {
    randomNum(min, max) {
      min = Math.ceil(min)
      max = Math.floor(max)
      return Math.floor(Math.random() * (max - min + 1)) + min
    },
    getRandomColor() {
      const r = this.randomNum(0, 255)
      const g = this.randomNum(0, 255)
      const b = this.randomNum(0, 255)
      return `rgb(${r}, ${g}, ${b})`
    },
    handleClick(desc) {
      this.color = this.getRandomColor()
      this.$emit('selectDog', desc)
    },
  },
}
</script>

<style lang="less" scoped>
.dog {
  display: inline-block;
  margin: 5px;
  width: 200px;
  box-shadow: 0 0 23px #ccc;
  .dog-img {
    height: 204px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    img {
      width: 100%;
    }
  }
  .dog-desc {
    text-align: center;
    margin: 0;
    line-height: 30px;
    color: #7e7474;
    font-size: 14px;
  }
}
</style>
